<?php

namespace app\api\controller\v1\user;

use app\middleware\ApiAuth;
use think\Request;
use think\facade\Validate;
use think\validate\ValidateRule;
use app\api\model\UserModel;
use think\response\Json;
class Index
{
    protected $middleware = [ApiAuth::class];

    /**用户重新绑定
     * @return mixed
     * @throws \WxPayException
     */
    public function ChoiceCompany(Request $request)
    {
        $input['openid'] = $request->post('openid'); //openid
        $input['role_type'] = $request->post('role_type'); // 类型 1：老板 2：员工
        $input['group_name'] = $request->post('group_name'); // 公司名称
        // 参数校验
        $validate = Validate::rule([
            'group_name' => ValidateRule::isRequire(),
            'role_type' => ValidateRule::isRequire(),
            'openid' => ValidateRule::isRequire(),
        ]);
        if (!$validate->check($input)) {
            return jsonFail($validate->getError());
        }
        //逻辑处理
        return UserModel::ChoiceCompany($input);
    }

    /**用户获取信息
     * @return mixed
     * @throws \WxPayException
     */
    public function UserInfo(Request $request)
    {
        $input['openid'] = $request->post('openid'); //openid
        // 参数校验
        $validate = Validate::rule([
            'openid' => ValidateRule::isRequire(),
        ]);
        if (!$validate->check($input)) {
            return jsonFail($validate->getError());
        }
        //逻辑处理
        return UserModel::UserInfo($input);
    }

    /**用户查看下单统计
     * @param Request $request
     * @return Json
     */
    public function OrderStatistics(Request $request)
    {
        $input['group_id'] = $request->post('group_id'); //公司id
        // 参数校验
        $validate = Validate::rule([
            'group_id' => ValidateRule::isRequire(),
        ]);
        if (!$validate->check($input)) {
            return jsonFail($validate->getError());
        }
        //逻辑处理
        return UserModel::OrderStatistics($input);
    }
}
